<?php
// $Id$

/**
 * Controller_Dk 控制器
 */
class Controller_Dk extends Controller_Abstract
{

	function actionIndex()
	{
		$pagesize = 10;
		$page = intval($this->_context->pageNum)?intval($this->_context->pageNum):1;
		$pagination = NULL;
	    $this->get_param();
		$typeid = intval($this->_context->typeid);
		if ($typeid)
		{
			$ptypeid = Categorys::find('parentid = ?',$typeid)->setColumns('id')->asArray()->getAll();
			$ptypeid = Helper_Array::toHashmap($ptypeid, 'id','id');
			$ptypeid[] = $typeid;
			$data = Product::find("type in(".implode(',', ($ptypeid)).")")->limitPage($page,$pagesize)->fetchPagination($pagination)->order('id desc')->get();
				
		}else{
			$data = Product::find()->limitPage($page,$pagesize)->fetchPagination($pagination)->order('id desc')->get();
				
		}
		
		$this->_view['param'] 		= $this->param;
		$this->_view['pagination']	= $pagination;
		$this->_view['data']      	= $data;
	
	}
	
	function actionview()
	{
		$id = intval($this->_context->id);
		$data = Product::find('id = ?',$id)->getOne();
		$this->_view['data'] = $data;
	}
}


